//
//  YBNavigationController.m
//  ZCWL
//
//  Created by ios-dev on 16/2/29.
//  Copyright © 2016年 com.zcwljs.cnge.app. All rights reserved.
//

#import "YBNavigationController.h"
#import "YBDefine.h"
#import "UIImage+YB.h"

@interface YBNavigationController ()

@end

@implementation YBNavigationController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupNavigation];
}

- (void)setupNavigation
{
    [self.navigationBar setBackgroundImage:[UIImage imageWithColor:[[UIColor redColor] colorWithAlphaComponent:1]] forBarMetrics:UIBarMetricsDefault];
    [self.navigationBar setShadowImage:[UIImage new]];
    
    [self.navigationBar setBarTintColor:[UIColor whiteColor]];
    [self.navigationBar setTintColor:[UIColor whiteColor]];
    self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    
    if (!self.viewControllers.count) {
        
    } else {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    [super pushViewController:viewController animated:animated];
}

- (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers animated:(BOOL)animated
{
    if (viewControllers.count>1) {
        [viewControllers enumerateObjectsUsingBlock:^(UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (idx) {
                obj.hidesBottomBarWhenPushed = YES;
            }
        }];
    }
    [super setViewControllers:viewControllers animated:animated];
}


@end
